package com.example.d2_buffered_stream;

import java.io.*;

/**
 * 目标：掌握字节缓冲流的作用 - 对原始流进行包装提升原始流读写的性能
 */
public class BufferedInputStreamTest1 {
    public static void main(String[] args) {
        try (
                InputStream is = new FileInputStream("day-20\\src\\yu02.txt");
                // 1.定义一个字节缓冲输入流包装原始的字节输入流
                InputStream bis = new BufferedInputStream(is);

                OutputStream os = new FileOutputStream("day-20\\src\\yu02_back.txt");
                // 2.把原始的字节输入流包装成字节缓冲输入流
                OutputStream bos = new BufferedOutputStream(os);
        ) {
            int len;
            byte[] buffer = new byte[1024];
            while ((len = bis.read(buffer)) != -1) {
                bos.write(buffer, 0, len);
            }
            System.out.println("复制完毕");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
